﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace Program10
{
    /// <summary>
    /// 加密类
    /// </summary>
    public class Encryption
    {
        public static readonly byte[] SaltKeys =
        {
            0xfa,0x5e,0x65,0x77,0xfe,0x95,0xa0,0x16,0x65,0x20,0x65,0x31,0xff
        };
        public static string GetEncryptString(string str)
        {
            var md5 = MD5.Create();
            var sha512 = SHA512.Create();
            //将字符转换成二进制数组

            var bitArray = Encoding.GetEncoding("UTF-8").GetBytes(str);

            //进行加密
            var md5BitArray = sha512.ComputeHash( md5.ComputeHash(bitArray).Concat(SaltKeys).ToArray());

            var encryptStr = "";
            for (int i = 0; i < md5BitArray.Length; i++)
            {
                encryptStr += md5BitArray[i].ToString("x2");
            }
            md5.Clear();
            sha512.Clear();
            return encryptStr;
        }
        //public static string GetSHA(string str)
        //{
        //    var sha = SHA1.Create();

        //    //将字符转换成二进制数组

        //    var bitArray = Encoding.GetEncoding("UTF-8").GetBytes(str);

        //    //进行加密
        //    var shaBitArray = sha.ComputeHash(bitArray);

        //    var encryptStr = "";
        //    for (int i = 0; i < shaBitArray.Length; i++)
        //    {
        //        encryptStr += shaBitArray[i].ToString("x2");
        //    }
        //    sha.Clear();
        //    return encryptStr;
        //}
    }
}
